package logic

import (
	"baidutieba/models/mysql"
	"context"

	"baidutieba/tiebarpc/internal/svc"
	"baidutieba/tiebarpc/tiebarpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type RateListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewRateListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RateListLogic {
	return &RateListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *RateListLogic) RateList(in *tiebarpc.RateListRequest) (*tiebarpc.RateListResponse, error) {
	// todo: add your logic here and delete this line
	var rate []mysql.Rate
	mysql.DB.Debug().Limit(10).Order("context desc").Find(&rate)
	var rateList []*tiebarpc.TieRateList
	for _, m := range rate {
		list := tiebarpc.TieRateList{
			UserId:  m.UserId,
			TieBaId: m.TieBaId,
			Context: m.Context,
		}
		rateList = append(rateList, &list)
	}
	return &tiebarpc.RateListResponse{
		List: rateList,
	}, nil
}
